package cn.ibizlab.odoo.core.odoo_mail.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Imail_statistics_report;
import cn.ibizlab.odoo.core.odoo_mail.domain.Mail_statistics_report;
import cn.ibizlab.odoo.core.odoo_mail.filter.Mail_statistics_reportSearchContext;
import cn.ibizlab.odoo.core.odoo_mail.service.IMail_statistics_reportService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[群发邮件阶段] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Mail_statistics_reportServiceImpl implements IMail_statistics_reportService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Imail_statistics_reportClientService mail_statistics_reportClientService;

    @Override
    public boolean update(Mail_statistics_report mail_statistics_report) {
        boolean bOk = false ;
        Imail_statistics_report clientModel = this.convert2Model(mail_statistics_report,null);
        mail_statistics_reportClientService.update(clientModel) ;
        this.convert2Domain(clientModel,mail_statistics_report) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //mail_statistics_reportClientService.removeBatch(mail_statistics_reports) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Imail_statistics_report clientModel = mail_statistics_reportClientService.createModel();
        clientModel.setId(id);
        mail_statistics_reportClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Mail_statistics_report> mail_statistics_reports, int batchSize) {

                        //mail_statistics_reportClientService.createBatch(mail_statistics_reports,batchSize) ;

    }

    @Override
    public Mail_statistics_report get(Integer id) {
        Imail_statistics_report clientModel = mail_statistics_reportClientService.createModel();
        clientModel.setId(id);
        mail_statistics_reportClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Mail_statistics_report get(Mail_statistics_report mail_statistics_report) {
        Mail_statistics_report retmail_statistics_report = this.get(mail_statistics_report.getId()) ;
    	BeanCopier copier=BeanCopier.create(retmail_statistics_report.getClass(), mail_statistics_report.getClass(), false);
        copier.copy(retmail_statistics_report, mail_statistics_report, null);
        return mail_statistics_report ;
    }

    @Override
    public boolean create(Mail_statistics_report mail_statistics_report) {
        boolean bOk = false ;
        Imail_statistics_report clientModel = this.convert2Model(mail_statistics_report,null);
        mail_statistics_reportClientService.create(clientModel) ;
        this.convert2Domain(clientModel,mail_statistics_report);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Mail_statistics_report> mail_statistics_reports, int batchSize) {

        //mail_statistics_reportClientService.updateBatch(mail_statistics_reports,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Mail_statistics_report> searchDefault(Mail_statistics_reportSearchContext context) {
        List<Mail_statistics_report> list = new ArrayList<Mail_statistics_report>();
        Page<cn.ibizlab.odoo.core.client.model.Imail_statistics_report> clientModelList = mail_statistics_reportClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imail_statistics_report clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Mail_statistics_report>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Imail_statistics_report convert2Model(Mail_statistics_report domain , Imail_statistics_report model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = mail_statistics_reportClientService.createModel() ;
        }

         if(domain.getClickedDirtyFlag())
            model.setClicked(domain.getClicked());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getBouncedDirtyFlag())
            model.setBounced(domain.getBounced());
         if(domain.getStateDirtyFlag())
            model.setState(domain.getState());
         if(domain.getRepliedDirtyFlag())
            model.setReplied(domain.getReplied());
         if(domain.getCampaignDirtyFlag())
            model.setCampaign(domain.getCampaign());
         if(domain.getScheduled_dateDirtyFlag())
            model.setScheduled_date(domain.getScheduled_date());
         if(domain.getSentDirtyFlag())
            model.setSent(domain.getSent());
         if(domain.getEmail_fromDirtyFlag())
            model.setEmail_from(domain.getEmail_from());
         if(domain.getDeliveredDirtyFlag())
            model.setDelivered(domain.getDelivered());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getOpenedDirtyFlag())
            model.setOpened(domain.getOpened());
        return model ;
    }

    public Mail_statistics_report convert2Domain( Imail_statistics_report model ,Mail_statistics_report domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Mail_statistics_report();
        }

        if(model.getClickedDirtyFlag())
            domain.setClicked(model.getClicked());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getBouncedDirtyFlag())
            domain.setBounced(model.getBounced());
        if(model.getStateDirtyFlag())
            domain.setState(model.getState());
        if(model.getRepliedDirtyFlag())
            domain.setReplied(model.getReplied());
        if(model.getCampaignDirtyFlag())
            domain.setCampaign(model.getCampaign());
        if(model.getScheduled_dateDirtyFlag())
            domain.setScheduled_date(model.getScheduled_date());
        if(model.getSentDirtyFlag())
            domain.setSent(model.getSent());
        if(model.getEmail_fromDirtyFlag())
            domain.setEmail_from(model.getEmail_from());
        if(model.getDeliveredDirtyFlag())
            domain.setDelivered(model.getDelivered());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getOpenedDirtyFlag())
            domain.setOpened(model.getOpened());
        return domain ;
    }


}
